home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / npurge11 / ndwalk.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  1KB  |  53 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <nit.h>
  4. #include <ntt.h>
  5.  
  6. #define ABORT(msg) \
  7.     fprintf(stderr,"%s at %d in %s\n",msg,__LINE__,__FILE__); \
  8.     exit(255);
  9.     
  10. static int result;
  11. static char scratchPad[10];
  12.  
  13.     
  14. void WalkDirectory(BYTE directoryHandle, void (*func)(BYTE handle))
  15. {
  16. char dirName[16];
  17.  
  18. int  sequenceNumber;
  19.  
  20. BYTE newDirectoryHandle;
  21.  
  22.  
  23.     sequenceNumber = 0;
  24.  
  25.     for(;;) {
  26.         result = ScanDirectoryInformation(
  27.                                 directoryHandle,
  28.                                 "*",
  29.                                 &sequenceNumber,
  30.                                 dirName,
  31.                                 (BYTE *) scratchPad,
  32.                                 (long *) scratchPad,
  33.                                 (BYTE *) scratchPad );
  34.  
  35.         if (result) return;
  36.  
  37.         result = AllocTemporaryDirectoryHandle(directoryHandle,dirName,'[',
  38.                              &newDirectoryHandle,scratchPad);
  39.         if (result) {
  40.             ABORT("Couldn't allocate a temporary directory handle");
  41.         }
  42.         
  43.         (*func) (newDirectoryHandle);
  44.  
  45.         WalkDirectory(newDirectoryHandle,func);
  46.  
  47.         if (DeallocateDirectoryHandle(newDirectoryHandle)) {
  48.             ABORT("Couldn't deallocate a temporary directory handle");
  49.         }
  50.     }
  51. }
  52.  
  53.